// Learn cc.Class:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
// Learn Attribute:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html

cc.Class({
    extends: cc.Component,

    properties: {
        Button_Nodes:[cc.Node],
        PlayerInfoBtns:[cc.Node],
        MainView:cc.Node,
        SelPlayerView:cc.Node,
      
    },



    onChangeScene(){
        cc.log("点击切换场景");
        cc.director.loadScene("GameScene");
    },

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {},
    initView(){
        this.MainView.setPosition(0,0);
        this.SelPlayerView.setPosition(0,0);
        this.MainView.active= true;
        this.SelPlayerView.active = false;
    },
    start () {

       this.initView();


        this.button_positions= new Array();
        for (let i = 0; i < this.Button_Nodes.length; i++) {
            this.button_positions[i] = this.Button_Nodes[i].getPosition();
            
        }

        for (let i = 0; i < this.PlayerInfoBtns.length; i++) {
          
            var script = this.PlayerInfoBtns[i].getChildByName("pressed");
            script.active=false;
            this.PlayerInfoBtns[i].on(cc.Node.EventType.TOUCH_START, this.touchShowPressedImg, this);
            this.PlayerInfoBtns[i].on(cc.Node.EventType.TOUCH_END, this.touchHidePressedImg, this);
            this.PlayerInfoBtns[i].on(cc.Node.EventType.TOUCH_CANCEL, this.touchHidePressedImg, this);
        }
    
    },
    
    touchShowPressedImg(target){
        var script = target.target.getChildByName("pressed");
        script.active=true;
    },
    touchHidePressedImg(target){
        var script = target.target.getChildByName("pressed");
        script.active=false;
    },
    onActionBtnOutOrIn(out){
        for (let i = 0; i < this.Button_Nodes.length; i++) {
            var time = cc.delayTime(0.1*i);
            var moveTo;
            if(out){
                moveTo = cc.moveTo(0.3,350,this.button_positions[i].y);
            }else{
                moveTo = cc.moveTo(0.3,this.button_positions[i]);
            }
            var seq = cc.sequence(time,moveTo);
            this.Button_Nodes[i].runAction(seq);
        }
    },
    openSelectPlayerView(){
        this.MainView.active= false;
        this.SelPlayerView.active = true;
        
    },
    openMainView(){
        this.MainView.active= true;
        this.SelPlayerView.active = false;
        
    },
    // update (dt) {},
});
